package com.xiantm.study.thread.towparsetermination;

public class InterruptTest {

    public static void main(String[] args) {

        Thread thread = new MyThread();
        thread.start();
        try {
            Thread.sleep(1000);
//            System.out.println(thread.isInterrupted());
        } catch (InterruptedException interruptedException) {
            interruptedException.printStackTrace();
        }
        thread.interrupt();
    }

   private static class MyThread extends Thread{
       @Override
       public void run() {
//           try {


           while (true){
               System.out.println("thread is running.");
               try {
                   Thread.sleep(2000);
               } catch (InterruptedException interruptedException) {
                   interruptedException.printStackTrace();
                   Thread.currentThread().interrupt();
               }
           }
//           } catch (Exception e){ }
       }
   }
}
